<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      style="display: flex;flex-direction: row;flex-wrap: wrap;justify-content: space-between;">
      <el-form-item label="菜品名" prop="dishname">
        <el-input v-model="queryParams.dishname" placeholder="请输入菜品名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="餐厅ID" prop="categoryid">
        <el-input v-model="queryParams.categoryid" placeholder="请输入餐厅ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input v-model="queryParams.price" placeholder="请输入价格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="介绍" prop="description">
        <el-input v-model="queryParams.description" placeholder="请输入介绍" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="口味1" prop="option1">
        <el-input v-model="queryParams.option1" placeholder="请输入口味1" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="口味2" prop="option2">
        <el-input v-model="queryParams.option2" placeholder="请输入口味2" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="口味3" prop="option3">
        <el-input v-model="queryParams.option3" placeholder="请输入口味3" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="口味4" prop="option4">
        <el-input v-model="queryParams.option4" placeholder="请输入口味4" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="类别" prop="species">
        <el-input v-model="queryParams.species" placeholder="请输入类别" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="推荐指数" prop="recommend">
        <el-input v-model="queryParams.recommend" placeholder="请输入推荐指数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['ordercheck:dishcheck:add']">新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['ordercheck:dishcheck:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['ordercheck:dishcheck:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ordercheck:dishcheck:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dishcheckList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="菜品ID" align="center" prop="dishid" />
      <el-table-column label="菜品名" align="center" prop="dishname" />
      <el-table-column label="餐厅ID" align="center" prop="categoryid" />
      <el-table-column
        label="菜品图片"
        prop="picture"
        align="center"
      >
        <template slot-scope="scope">
          <el-image
            style="width: 80px; height: 80px;"
            :src="scope.row.picture"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="剩余数量" align="center" prop="quantity" />
      <el-table-column label="介绍" align="center" prop="description" />
      <el-table-column label="口味1" align="center" prop="option1" />
      <el-table-column label="口味2" align="center" prop="option2" />
      <el-table-column label="口味3" align="center" prop="option3" />
      <el-table-column label="口味4" align="center" prop="option4" />
      <el-table-column label="审核状态" align="center" prop="status" >
        <template slot-scope="scope">
          {{scope.row.status==1?"通过":"未通过"}}
        </template>
      </el-table-column>
      <el-table-column label="类别" align="center" prop="species" />
      <el-table-column label="推荐指数" align="center" prop="recommend" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-circle-check" @click="handlethrough(scope.row)"
            v-hasPermi="['ordercheck:dishcheck:through']">通过</el-button>

                   <!-- <el-button size="mini" type="text" icon="el-icon-circle-check" @click="handlethrough(scope.row)"
            v-hasPermi="['ordercheck:dishcheck:through']">通过</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-circle-check" @click="handlethrough(scope.row)"
            v-hasPermi="['ordercheck:dishcheck:edit']">通过</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['ordercheck:dishcheck:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改菜品审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="菜品名" prop="dishname">
          <el-input v-model="form.dishname" placeholder="请输入菜品名" />
        </el-form-item>
        <el-form-item label="餐厅ID" prop="categoryid">
          <el-input v-model="form.categoryid" placeholder="请输入餐厅ID" />
        </el-form-item>
        <el-form-item label="参考图片" prop="picture">
          <el-input v-model="form.picture" placeholder="请输入参考图片" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="剩余数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入剩余数量" />
        </el-form-item>
        <el-form-item label="介绍" prop="description">
          <el-input v-model="form.description" placeholder="请输入介绍" />
        </el-form-item>
        <el-form-item label="口味1" prop="option1">
          <el-input v-model="form.option1" placeholder="请输入口味1" />
        </el-form-item>
        <el-form-item label="口味2" prop="option2">
          <el-input v-model="form.option2" placeholder="请输入口味2" />
        </el-form-item>
        <el-form-item label="口味3" prop="option3">
          <el-input v-model="form.option3" placeholder="请输入口味3" />
        </el-form-item>
        <el-form-item label="口味4" prop="option4">
          <el-input v-model="form.option4" placeholder="请输入口味4" />
        </el-form-item>
        <el-form-item label="类别" prop="species">
          <el-input v-model="form.species" placeholder="请输入类别" />
        </el-form-item>
        <el-form-item label="推荐指数" prop="recommend">
          <el-input v-model="form.recommend" placeholder="请输入推荐指数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listDishcheck,
    getDishcheck,
    delDishcheck,
    addDishcheck,
    updateDishcheck,
    throDishcheck
  } from "@/api/ordercheck/dishcheck";

  export default {
    name: "Dishcheck",
    data() {
      return {
        fileupload: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 菜品审核表格数据
        dishcheckList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          dishname: null,
          categoryid: null,
          picture: null,
          price: null,
          quantity: null,
          description: null,
          option1: null,
          option2: null,
          option3: null,
          option4: null,
          status: null,
          species: null,
          recommend: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          dishname: [{
            required: true,
            message: "菜品名不能为空",
            trigger: "blur"
          }],
          categoryid: [{
            required: true,
            message: "餐厅ID不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      file() {
        this.fileupload = true;
      },
      //单击确定按钮或单击弹窗外的部分后弹窗隐藏，并自动刷新当前页
      handleClose(done) {
        this.fileupload=false;
        this.loadFileTalbe();//该方法为页面初始化时数据表格查询展示的功能，不做过多赘述，理解为表格页面刷新功能。
      },
      //弹窗内删除文件时的提示确认功能
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${file.name}？`);
      },
      //删除功能的具体展示
      handleRemove(file, fileList) {
      	//removeFile为访问java端的api链接，参数uid为element上传控件自带的 id
        removeFile({id:file.uid}).then(resp => {
          if (resp && resp.data) {
            if (resp.data == true) {
              this.$message({
                showClose: true,
                message: "删除成功！",
                type: "success"
              });
            } else {
              this.$message({
                showClose: true,
                message: "删除失败！",
                type: "error"
              });
            }
          }
        }).catch(error => {
          console.log("error", error.message);
        })
      },
      /** 查询菜品审核列表 */
      getList() {
        this.loading = true;
        listDishcheck(this.queryParams).then(response => {
          this.dishcheckList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          dishid: null,
          dishname: null,
          categoryid: null,
          picture: null,
          price: null,
          quantity: null,
          description: null,
          option1: null,
          option2: null,
          option3: null,
          option4: null,
          status: 0,
          species: null,
          recommend: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.dishid)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加菜品审核";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const dishid = row.dishid || this.ids
        getDishcheck(dishid).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改菜品审核";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.dishid != null) {
              updateDishcheck(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addDishcheck(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const dishids = row.dishid || this.ids;
        this.$modal.confirm('是否确认删除菜品审核编号为"' + dishids + '"的数据项？').then(function() {
          return delDishcheck(dishids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 通过按钮操作 */
      handlethrough(row) {
        const dishids = row.dishid || this.ids;
        this.$modal.confirm('是否确认通过菜单审核编号为"' + dishids + '"的数据项？').then(function() {
          return throDishcheck(dishids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("审核通过操作成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('ordercheck/dishcheck/export', {
          ...this.queryParams
        }, `dishcheck_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
